<template>
  <div>
      <h2>欢迎来到清华大学</h2>
      <p>
          罗迪克就是老师讲课老师就考了九十分神经科大夫
          看来是积分卢卡斯京东方立刻就士大夫
      </p>
      <button @click="hotClick">今日头条</button>
      <button @click="newsClick">内容详情</button>
      <router-view/>
  </div>
</template>

<script>
export default {
  name: 'Home',
  data(){
    return{
      link:'/home/hot'
    }
  },
  //vue的生命周期
  created(){
    document.title = "首页"
    console.log('home created');
  },
  //挂载到el
  mounted(){
    console.log('home created');
  },
  //更新
  updated(){
    console.log('home updated');
  },
  //销毁
  destroyed(){
    console.log('home destroyed');
  },
  activated(){
    console.log("home activated---------");
    this.$router.replace(this.link).catch(err=>err);
  },
  deactivated(){
    console.log("home deactivated---------");
  },
  //组件内导航守卫
  beforeRouteEnter(to,from,next){
    console.log('home---------beforeRouteEnter ');
    next();
  },
  beforeRouteUpdate(to,from,next){
    console.log('home---------beforeRouteUpdate ');
    next();
  },
  beforeRouteLeave(to,from,next){
    console.log('home---------beforeRouteLeave ');
    this.link = this.$route.path;
    next();
  },

  methods:{
    hotClick(){
      this.$router.push('/home/hot').catch(err => err);
    },
    newsClick(){
      this.$router.push('/home/news').catch(err =>err);
    },
    
  }
}
</script>

<style scope>

</style>